package com.gr.analys;

public class Word {
	
	protected static boolean isTokenChar(char c) 
	{
	       return Character.isLetterOrDigit(c);
	    //	return Character.isLetter(c);
	}
	
	public static int contain(String s1)
	{
                if(s1.length()==0) return 0; 
		int k=0;
		if(isTokenChar(s1.charAt(0))==true) k++;
		for(int i=0;i<s1.length()-1;i++)
		{		
			if(isTokenChar(s1.charAt(i))==false)
			{
				if(isTokenChar(s1.charAt(i+1))==true) k++;	
			}
			
		}
		return k;
	}
	public static String substring(String s1, int start,int num)
	{
		int k=0;
		int i=start;
                
		if(isTokenChar(s1.charAt(start))==true) k++;
		while(k<num)
		{
			if(isTokenChar(s1.charAt(i))==false)
			{
				if(i+1>=s1.length()) break;
				if(isTokenChar(s1.charAt(i+1))==true) k++;	
			}
			i++;
    	        }
		while(isTokenChar(s1.charAt(i))==true)
			{
				i++;
				if(i>=s1.length()) break;
			}
		return s1.substring(start,i);
	}
	public static Token1 substringT(String s1, int start, int num)
	{
		String s;
		s=substring(s1,start, num);
		int k=start;
		while(isTokenChar(s1.charAt(k++))==false)
		{
			if (k>=s1.length()) break;
		}
		Token1 _token=new Token1(s,k-1);
		return _token;
	}
}
